﻿
using DryIoc;
using Example;
using LaserAutoTest.Application;
using Microsoft.Extensions.DependencyInjection;
using Prism.DryIoc;
using Prism.Ioc;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Documents;

namespace LaserAutoTest.UI.Extensions
{
    public static class ServiceExtension
    {
        public static void RegisteServices(this IServiceCollection services)//this IContainerRegistry containerRegistry
        {
            //containerRegistry.RegisterScoped<ITcpService, TcpService>();
            //containerRegistry.RegisterScoped<IUserService, UserService>();
            var uploadWay = ConfigurationManager.AppSettings["UploadWay"];

            services.Scan(scan =>
            {
                scan.FromAssemblyOf<GlobalValues>()
                    .AddClasses(classes => classes.Where(t => t.Name.EndsWith("Service", StringComparison.OrdinalIgnoreCase)))
                    .AsImplementedInterfaces()
                    .WithScopedLifetime();

                if (!string.IsNullOrEmpty(uploadWay))
                {
                    scan.FromAssemblyOf<GlobalValues>()
                              .AddClasses(classes => classes.Where(t =>
                                t.Name.EndsWith("Service", StringComparison.OrdinalIgnoreCase) &&
                                t.Name.Contains(uploadWay, StringComparison.OrdinalIgnoreCase)))
                              .AsImplementedInterfaces().WithScopedLifetime();
                }
            });

           

        }
    }
}
